<!DOCTYPE html>
<html>
<head>
<title>Physics Diagrams</title>
</head>
<body>
<canvas id="myCanvas" width="800" height="350"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

// --- General Styles ---
ctx.strokeStyle = 'black';
ctx.lineWidth = 2;
ctx.font = '18px Arial';
ctx.fillStyle = 'black';

// Function to draw an arrowhead
function drawArrowhead(x, y, angle) {
    const headlen = 10;
    ctx.beginPath();
    ctx.moveTo(x, y);
    ctx.lineTo(x - headlen * Math.cos(angle - Math.PI / 6), y - headlen * Math.sin(angle - Math.PI / 6));
    ctx.moveTo(x, y);
    ctx.lineTo(x - headlen * Math.cos(angle + Math.PI / 6), y - headlen * Math.sin(angle + Math.PI / 6));
    ctx.stroke();
}

// --- Diagram 甲 (Block on a surface) ---
const x1_start = 30;
const y1_base = 250;

// Ground
ctx.beginPath();
ctx.moveTo(x1_start, y1_base);
ctx.lineTo(x1_start + 240, y1_base);
ctx.stroke();
// Hatching for the ground
ctx.lineWidth = 1;
for (let i = 0; i < 24; i++) {
    ctx.beginPath();
    ctx.moveTo(x1_start + i * 10, y1_base);
    ctx.lineTo(x1_start + 10 + i * 10, y1_base + 10);
    ctx.stroke();
}
ctx.lineWidth = 2;

// Block
ctx.beginPath();
ctx.rect(x1_start + 40, y1_base - 60, 100, 60);
ctx.stroke();

// Force Arrow F
ctx.beginPath();
ctx.moveTo(x1_start + 140, y1_base - 30);
ctx.lineTo(x1_start + 200, y1_base - 30);
ctx.stroke();
drawArrowhead(x1_start + 200, y1_base - 30, 0);

// Labels for Diagram 甲
ctx.font = 'italic 20px Arial';
ctx.fillText('F', x1_start + 165, y1_base - 35);
ctx.font = '20px Arial';
ctx.fillText('甲', x1_start + 110, y1_base + 40);


// --- Diagram 乙 (F-t graph) ---
const ox2 = 330;
const oy2 = 280;
const x_len2 = 180;
const y_len2 = 180;
const t_scale2 = x_len2 / 6; // 30px per second
const f_scale2 = y_len2 / 3; // 60px per Newton

// Axes
ctx.beginPath();
ctx.moveTo(ox2, oy2);
ctx.lineTo(ox2, oy2 - y_len2 - 20); // Y-axis
ctx.moveTo(ox2, oy2);
ctx.lineTo(ox2 + x_len2 + 20, oy2); // X-axis
ctx.stroke();
drawArrowhead(ox2, oy2 - y_len2 - 20, Math.PI / 2);
drawArrowhead(ox2 + x_len2 + 20, oy2, 0);

// Axis Labels
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.font = 'italic 18px Arial';
ctx.fillText('F', ox2 + 10, oy2 - y_len2 - 5);
ctx.font = '18px Arial';
ctx.fillText('/ N', ox2 + 25, oy2 - y_len2 - 5);

ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.font = 'italic 18px Arial';
ctx.fillText('t', ox2 + x_len2 + 10, oy2 + 10);
ctx.font = '18px Arial';
ctx.fillText('/ s', ox2 + x_len2 + 20, oy2 + 10);

// Ticks and Tick Labels
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('2', ox2 + 2 * t_scale2, oy2 + 5);
ctx.fillText('4', ox2 + 4 * t_scale2, oy2 + 5);
ctx.fillText('6', ox2 + 6 * t_scale2, oy2 + 5);

ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
ctx.fillText('1', ox2 - 5, oy2 - 1 * f_scale2);
ctx.fillText('2', ox2 - 5, oy2 - 2 * f_scale2);
ctx.fillText('3', ox2 - 5, oy2 - 3 * f_scale2);

ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('0', ox2-5, oy2+5);

// Dashed lines
ctx.save();
ctx.setLineDash([5, 5]);
ctx.lineWidth = 1;
// Horizontal helpers
ctx.beginPath();
ctx.moveTo(ox2, oy2 - 3 * f_scale2);
ctx.lineTo(ox2 + 4 * t_scale2, oy2 - 3 * f_scale2);
ctx.moveTo(ox2, oy2 - 2 * f_scale2);
ctx.lineTo(ox2 + 6 * t_scale2, oy2 - 2 * f_scale2);
ctx.stroke();
// Vertical helpers
ctx.beginPath();
ctx.moveTo(ox2 + 2 * t_scale2, oy2);
ctx.lineTo(ox2 + 2 * t_scale2, oy2 - 3 * f_scale2);
ctx.moveTo(ox2 + 4 * t_scale2, oy2);
ctx.lineTo(ox2 + 4 * t_scale2, oy2 - 3 * f_scale2);
ctx.moveTo(ox2 + 6 * t_scale2, oy2);
ctx.lineTo(ox2 + 6 * t_scale2, oy2 - 2 * f_scale2);
ctx.stroke();
ctx.restore();

// Solid graph line (drawn over dashed lines where applicable)
ctx.beginPath();
ctx.moveTo(ox2 + 2 * t_scale2, oy2 - 3 * f_scale2);
ctx.lineTo(ox2 + 4 * t_scale2, oy2 - 3 * f_scale2);
ctx.moveTo(ox2 + 4 * t_scale2, oy2 - 2 * f_scale2);
ctx.lineTo(ox2 + 6 * t_scale2, oy2 - 2 * f_scale2);
ctx.stroke();

// Diagram Label
ctx.textAlign = 'center';
ctx.textBaseline = 'alphabetic';
ctx.font = '20px Arial';
ctx.fillText('乙', ox2 + x_len2 / 2, oy2 + 40);


// --- Diagram 丙 (v-t graph) ---
const ox3 = 560;
const oy3 = 280;
const x_len3 = 180;
const y_len3 = 120;
const t_scale3 = x_len3 / 6; // 30px per second
const v_scale3 = y_len3 / 2; // 60px per m/s

// Axes
ctx.beginPath();
ctx.moveTo(ox3, oy3);
ctx.lineTo(ox3, oy3 - y_len3 - 20); // Y-axis
ctx.moveTo(ox3, oy3);
ctx.lineTo(ox3 + x_len3 + 20, oy3); // X-axis
ctx.stroke();
drawArrowhead(ox3, oy3 - y_len3 - 20, Math.PI / 2);
drawArrowhead(ox3 + x_len3 + 20, oy3, 0);

// Axis Labels
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.font = 'italic 18px Arial';
ctx.fillText('v', ox3 + 10, oy3 - y_len3 - 5);
ctx.font = '18px Arial';
ctx.fillText('/ (m·s⁻¹)', ox3 + 22, oy3 - y_len3 - 5);

ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.font = 'italic 18px Arial';
ctx.fillText('t', ox3 + x_len3 + 10, oy3 + 10);
ctx.font = '18px Arial';
ctx.fillText('/ s', ox3 + x_len3 + 20, oy3 + 10);

// Ticks and Tick Labels
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('2', ox3 + 2 * t_scale3, oy3 + 5);
ctx.fillText('4', ox3 + 4 * t_scale3, oy3 + 5);
ctx.fillText('6', ox3 + 6 * t_scale3, oy3 + 5);

ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
ctx.fillText('1', ox3 - 5, oy3 - 1 * v_scale3);
ctx.fillText('2', ox3 - 5, oy3 - 2 * v_scale3);

ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillText('0', ox3-5, oy3+5);

// Dashed lines
ctx.save();
ctx.setLineDash([5, 5]);
ctx.lineWidth = 1;
// Vertical
ctx.beginPath();
ctx.moveTo(ox3 + 4 * t_scale3, oy3);
ctx.lineTo(ox3 + 4 * t_scale3, oy3 - 2 * v_scale3);
ctx.moveTo(ox3 + 6 * t_scale3, oy3);
ctx.lineTo(ox3 + 6 * t_scale3, oy3 - 2 * v_scale3);
ctx.stroke();
// Horizontal
ctx.beginPath();
ctx.moveTo(ox3, oy3 - 2 * v_scale3);
ctx.lineTo(ox3 + 4 * t_scale3, oy3 - 2 * v_scale3);
ctx.stroke();
ctx.restore();

// Solid graph line
ctx.beginPath();
ctx.moveTo(ox3, oy3);
ctx.lineTo(ox3 + 2 * t_scale3, oy3);
ctx.lineTo(ox3 + 4 * t_scale3, oy3 - 2 * v_scale3);
ctx.lineTo(ox3 + 6 * t_scale3, oy3 - 2 * v_scale3);
ctx.stroke();

// Diagram Label
ctx.textAlign = 'center';
ctx.textBaseline = 'alphabetic';
ctx.font = '20px Arial';
ctx.fillText('丙', ox3 + x_len3 / 2, oy3 + 40);

</script>
</body>
</html>